const OrdersModel = require('../models/ordersModels')
const { successResponse, errorResponse } = require('../utils/response')


class OrdersController {
    static async getOrders(req, res) {
       
        try {
            const { id } = req.params
             console.log(req.query)
            const orders = await OrdersModel.getOrders(id)
            return res.send(successResponse(orders))
        } catch (error) {
            return res.status(500).send(errorResponse('Failed to fetch orders', error.message))
        }
    }
    static async addOrders(req, res) {
        try {
            const { order_number, username, order_time, amount,status,created_at } = req.body
            const orders = await OrdersModel.addOrders({ order_number, username, order_time, amount,status,created_at })
            return res.send(successResponse(orders))
        }catch (error) {
            return res.status(500).send(errorResponse('Failed to fetch orders', error.message))
        }
    }

    static async updateOrders(req, res) {
        try {
            const { id } = req.query
            const data= req.body
            const orders = await OrdersModel.updateOrders(id,data)
            return res.send(successResponse(orders))
        }catch (error) {
            return res.status(500).send(errorResponse('Failed to fetch orders', error.message))
        }
    }

    static async deleteOrders(req, res) {
        try {
            const { id } = req.query
            const orders = await OrdersModel.deleteOrders(id)
            return res.send(successResponse(orders))
        } catch (error) {
            return res.status(500).send(errorResponse('Failed to fetch orders', error.message))
        }
    }

}



module.exports = OrdersController